//保护统计信息页获取数据
function getStatistics() {
	$.getJSON("/rest/protectdata/getProtectInfo", function(result) {
		initVolView(result.vol);
		initManufacChart(result);
		initManufacTb(result);
	});
}
// 按电压等级统计
function initVolView(data) {
	$("#vol .text-green").html(data["500kV"]);
	$("#vol .text-yellow").html(data["220kV"]);
	$("#vol .text-blue").html(data["110kV"]);
	$("#vol .text-orange").html(data["35kV"]);
	$("#vol .text-black").html(data.other);
	$("#vol .text-red").html(data.total + "(个)");
}
// 按生产厂家划分
//数据格式为manufacturer:{manufacturer:[]}
function initManufacTb(data) {
	var columns = data.protecedTypes;
	columns.unshift("厂家");
	columns.push("合计");
	var dataList=[];
	for(var name in data.manufacturer){
		var list=data.manufacturer[name];
		list.unshift(name);
		dataList.push(list);
	}
	var opt = MyTable.getDefaultOptions();
	opt.paging = true;
	opt.searching = true;
	opt.ordering = true;
	opt.info = true;
	opt.lengthChange = true;
	var tb = new MyTable('manufactureTb', columns, opt);
	tb.setDataSet(dataList);
	tb.show();
	// 将表格中数据不为零的单元格变色
	tb.getTable().cells().every(function() {
		var data = this.data();
		if (data != "0" && this[0][0].column != 0 && this[0][0].column != (columns.length-1)) {
			$(this.node()).addClass("warning");
		}
	});
}
//chart
var manufacChart=new CategoryBar("manufactureChart");
function initManufacChart(dataObj){
	var protectTypes=dataObj.protecedTypes;
	var allManufacs=[];
	for(var manufac in dataObj.manufacturer){
		allManufacs.push(manufac);
	}
	manufacChart.setxAxis(allManufacs);
	for(var i in protectTypes){
		var protectType=protectTypes[i];
		var yValues=[];
		for(var manufac in dataObj.manufacturer){
			yValues.push(dataObj.manufacturer[manufac][i]);
		}
		manufacChart.setyAxis(yValues).setyAxisName(protectType);
	}
	manufacChart.setDataZoom(true).setDataZoomStartValue(0,5).setToolbox(false).show();
}
$("#chartTab").click(function(){
	var t1 = window.setInterval(function() {
		var w=parseInt($("#chartPane").css("width"));
		if (w != 0) {
			$("#manufactureChart").css("width",w);
			manufacChart.getChart().resize();
			window.clearInterval(t1);
		}
	}, 20);
});
